
const request = require('../../../utils/request');


Page({
    data: {
        mess: '',
        chatMess: [],
        scrollTop: '',
        msg: '主人，有什么不了解的可以问通通哦！',
        userHeaderUrl:''
    },
    onLoad: function() {
        //获取本地存储头像，名字
        let that = this
        wx.getStorage({
            key: 'user',
            success: function(res){
                console.log(res)
                that.setData({
                    userHeaderUrl: res.data.userHeaderUrl
                })
            }
        })
    },
    onReady: function() {
        wx.setNavigationBarTitle({
            title: '聊天'
        })
    },
    changeMess(e) {
        this.setData({
            mess: e.detail.value
        })
    },
    send() {
        let data = {};
        if(this.data.mess != ''){
            data.a = this.data.mess
            request.HttpRequst(true,'robot/askQuestion',false,'',{'keyword':this.data.mess,'token': wx.getStorageSync('sessionId')},"POST",false,res => {
                data.b = res.data;
                this.data.chatMess.push(data)
                this.setData({
                    chatMess:this.data.chatMess,
                    mess: ''
                })

                console.log(this.data.chatMess)
                let that = this
                wx.createSelectorQuery().select('#chat-con').boundingClientRect(function(e){
                    that.setData({
                        scrollTop: e.height
                    })
                    console.log(that.data.scrollTop)
                }).exec()
            })
        }
        
        
        
        
        
    }
})